package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.configuration.Config;
import com.example.demo.entity.AllData;
import com.example.demo.entity.VirusData;
import com.fasterxml.jackson.annotation.JsonAlias;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class mvc {

    @GetMapping("/index")
    public String hello(){
        return "index";
    }
    @GetMapping(value = "/fan", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String showBook(@RequestParam("args") String args) {


        //model.addAllAttributes("item",Config.allData);
        //ViewData["list"]= Config.allData;
        //return Config.allData;
        //Map<String,AllData> map=new HashMap<>();
        //map.put("list",Config.allData);
        //model.addAttribute("list", Config.allData.getAllVirusData().get(0));
        //map.addObject("list", Config.allData.getAllVirusData().get(0));

        List<VirusData> list=new ArrayList<>();
        if(args.equals("global")){
            list=Config.allData.getAllVirusData();
        }
        else {
            for(VirusData virusData:Config.allData.getAllVirusData()){
                if(args.equals(virusData.getCountry())){
                    list.add(virusData);
                }
            }
        }
        String json= JSON.toJSONString(list);
        list=null;
        return json;
    }

}
